<?php
include_once '../includes/common.php';
if($islogin==1){}else sysmsg("您还未登录，请先登录",2,'./login.php',true);
if(isset($_GET['id'])) {
$id=isset($_GET['id'])?intval($_GET['id']):sysmsg("参数错误",2,'./',true);
$row=$DB->get_row("SELECT * FROM authguao_program WHERE id='{$id}' limit 1");
if(!$row)sysmsg("授权平台不存在该程序",2,'./prolist.php',true);
$title='编辑程序';
include_once './header.php';
?>
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-header">
                编辑程序
            </div>
            <div class="card-body">
                <form class="form-horizontal layui-form">
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">程序名称：</label>
                        <input type="text" name="name" value="<?php echo $row['name']?>" class="form-control" placeholder="输入该程序名称" lay-verType="tips" lay-verify="required">
                    </div>
                    <div class="form-group mb-3">
                        <input type="file" id="file" onchange="fileUpload()" style="display:none;"/>
                        <label for="example-input-normal" style="font-weight: 500">程序图标：<span class="badge badge-success-lighten" onclick="fileView()">查看程序图标</span> <a href="javascript:fileSelect()" class="badge badge-danger-lighten">上传程序图标</a></label>
                        <input type="text" name="img" value="<?php echo $row['img']?>" class="form-control" placeholder="上传该程序图标" lay-verType="tips" lay-verify="required">
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">程序简介：</label>
                        <textarea name="desc" class="form-control" style="height:100px;" placeholder="简单概述一下该程序" lay-verType="tips" lay-verify="required"><?php echo $row['desc']?></textarea>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">程序授权码文件路径：</label>
                        <input type="text" name="authfile" value="<?php echo $row['authfile']?>" class="form-control" placeholder="输入该程序的授权码文件路径" lay-verType="tips" lay-verify="required">
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">程序安装包文件名：</label>
                        <input type="text" name="installer_name" value="<?php echo $row['installer_name']?>" class="form-control" placeholder="输入安装包下载文件名" lay-verType="tips" lay-verify="required">
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">程序更新包文件名：</label>
                        <input type="text" name="updater_name" value="<?php echo $row['updater_name']?>" class="form-control" placeholder="输入更新包下载文件名" lay-verType="tips" lay-verify="required">
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">程序验证授权：</label>
                        <select name="switch" class="form-control" lay-search lay-filter="switch"><option <?php echo $row['switch'] == 1 ? 'selected ' : '' ?>value="1">开启</option><option <?php echo $row['switch'] == 0 ? 'selected ' : '' ?>value="0">关闭</option></select>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">程序验证IP：</label>
                        <select name="ipauth" class="form-control" lay-search lay-filter="ipauth"><option <?php echo $row['ipauth'] == 0 ? 'selected ' : '' ?>value="0">关闭</option><option <?php echo $row['ipauth'] == 1 ? 'selected ' : '' ?>value="1">开启</option></select>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">程序更新开关：</label>
                        <select name="update" class="form-control" lay-search lay-filter="update"><option <?php echo $row['update'] == 1 ? 'selected ' : '' ?>value="1">开启</option><option <?php echo $row['update'] == 0 ? 'selected ' : '' ?>value="0">关闭</option></select>
                    </div>
                    <div id="frame_set1" style="<?php echo $row['update']==0?'display:none;':null; ?>">
                        <div class="form-group mb-3">
                            <label for="example-input-normal" style="font-weight: 500">程序最新版本号：</label>
                            <input type="text" name="ver" value="<?php echo $row['ver']?>" class="form-control">
                            <small><font color="red">说明：版本号类似于1.0 1.5 2.0 3.0 （显示用）</font></small>
                        </div>
                        <div class="form-group mb-3">
                            <label for="example-input-normal" style="font-weight: 500">程序最新版本序号：</label>
                            <input type="text" name="version" value="<?php echo $row['version']?>" class="form-control">
                            <small><font color="red">说明：版本<font color="blue">序</font>号类似于1000 1001 1002 （更新判断用）</font></small>
                        </div>
                        <div class="form-group mb-3">
                            <label for="example-input-normal" style="font-weight: 500">程序新版本信息：</label>
                            <textarea name="uplog" class="form-control" style="height:100px;"><?php echo $row['uplog']?></textarea>
                        </div>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">程序站点记录：</label>
                        <select name="addblock" class="form-control" lay-search lay-filter="addblock"><option <?php echo $row['addblock'] == 3 ? 'selected ' : '' ?>value="3">开启|记录盗版和正版</option><option <?php echo $row['addblock'] == 2 ? 'selected ' : '' ?>value="2">开启|记录正版</option><option <?php echo $row['addblock'] == 1 ? 'selected ' : '' ?>value="1">开启|记录盗版</option><option <?php echo $row['addblock'] == 0 ? 'selected ' : '' ?>value="0">关闭记录</option></select>
                    </div>
                    <div id="frame_set2" style="<?php echo $row['addblock']==0 || $row['addblock']==2?'display:none;':null; ?>">
                        <div class="form-group mb-3">
                            <label for="example-input-normal" style="font-weight: 500">程序未授权操作：</label>
                            <select name="block" class="form-control" lay-search lay-filter="block"><option <?php echo $row['block'] == 0 ? 'selected ' : '' ?>value="0">提示未授权</option><option <?php echo $row['block'] == 1 ? 'selected ' : '' ?>value="1">提示未授权|导入后门</option><option <?php echo $row['block'] == 2 ? 'selected ' : '' ?>value="2">提示未授权|导入黑页</option><option <?php echo $row['block'] == 3 ? 'selected ' : '' ?>value="3">提示未授权|自动黑站</option></select>
                        </div>
                        <div class="form-group mb-3">
                            <label for="example-input-normal" style="font-weight: 500">程序盗版显示内容：</label>
                            <textarea name="notauth_msg" class="form-control" style="height:100px;"><?php echo $row['notauth_msg']?></textarea>
                        </div>
                        <div class="form-group mb-3">
                            <label for="example-input-normal" style="font-weight: 500">程序授权到期显示内容：</label>
                            <textarea name="endauth_msg" class="form-control" style="height:100px;"><?php echo $row['endauth_msg']?></textarea>
                        </div>
                        <div class="form-group mb-3">
                            <label for="example-input-normal" style="font-weight: 500">程序授权封禁显示内容：</label>
                            <textarea name="errauth_msg" class="form-control" style="height:100px;"><?php echo $row['errauth_msg']?></textarea>
                        </div>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">程序是否运行：</label>
                        <select name="active" class="form-control" lay-search lay-filter="active"><option <?php echo $row['active'] == 1 ? 'selected ' : '' ?>value="1">1_是</option><option <?php echo $row['active'] == 0 ? 'selected ' : '' ?>value="0">0_否</option></select>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">程序授权销售价格：</label>
                        <input type="text" name="sqprice" value="<?php echo $row['sqprice']?>" placeholder="输入该程序的域名授权销售价格" class="form-control" lay-verType="tips" lay-verify="required">
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">程序授权商添加授权价格：</label>
                        <input type="text" name="sqprice2" value="<?php echo $row['sqprice2']?>" placeholder="输入该程序的授权商添加授权的价格" class="form-control" lay-verType="tips" lay-verify="required">
                        <small>价格应低于授权销售价格</small>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">程序超管添加授权价格：</label>
                        <input type="text" name="sqprice3" value="<?php echo $row['sqprice3']?>" placeholder="输入该程序的超管添加授权的价格" class="form-control" lay-verType="tips" lay-verify="required">
                        <small>价格应低于授权商添加授权价格</small>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">程序认证销售价格：</label>
                        <input type="text" name="rzprice" value="<?php echo $row['rzprice']?>" placeholder="输入该程序的易支付域名认证销售价格" class="form-control" lay-verType="tips" lay-verify="required">
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">程序授权商销售价格：</label>
                        <input type="text" name="sqsprice" value="<?php echo $row['sqsprice']?>" placeholder="输入该程序的授权商销售价格" class="form-control" lay-verType="tips" lay-verify="required">
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">程序超管添加授权商价格：</label>
                       <input type="text" name="sqsprice2" value="<?php echo $row['sqsprice2']?>" placeholder="输入该程序的超管添加授权商的价格" class="form-control" lay-verType="tips" lay-verify="required">
                       <small>价格应低于授权商销售价格</small>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">程序超管销售价格：</label>
                        <input type="text" name="cgprice" value="<?php echo $row['cgprice']?>" placeholder="输入该程序的超管销售价格" class="form-control" lay-verType="tips" lay-verify="required">
                    </div>
                    <button type="submit" class="btn btn-block btn-xs btn-outline-success" lay-submit lay-filter="submit_proedit">修 改</button>
                </form>
            </div>
        </div>
    </div>
</div>
<?php
include_once './bottom.php';
?>
<script type="text/javascript">
layui.use(['form'], function () {
    var form = layui.form;
    form.on('submit(submit_proedit)', function (data) {
        layer.alert('是否要执行当前操作？', {
            icon: 3, btn: ['确定', '取消'], btn1: function (layero, index) {
                proedit();
            }
        });
        return false;
    });
    form.on('select(addblock)', function(data){ 
        if(data.value == '1' || data.value == '3'){
            $("#frame_set2").show();
        }else{
            $("#frame_set2").hide();
        }
    });
    form.on('select(update)', function(data){ 
        if(data.value == '1'){
            $("#frame_set1").show();
        }else{
            $("#frame_set1").hide();
        }
    });
});
function fileSelect(){
    $("#file").trigger("click");
}
function fileView(){
    var img = $("input[name='img']").val();
    if(img=='') {
        layer.msg("请先上传图片，才能预览", {icon: 5});
        return;
    }
    if(img.indexOf('http') == -1)img = '../'+img;
    layer.open({
        type: 1,
        area: ['360px', '400px'],
        title: '程序图标查看',
        shade: 0.3,
        anim: 1,
        shadeClose: true,
        content: '<center><img width="300px" src="'+img+'"></center>'
    });
}
function fileUpload(){
    var fileObj = $("#file")[0].files[0];
    if (typeof (fileObj) == "undefined" || fileObj.size <= 0) {
        return;
    }
    var formData = new FormData();
    formData.append("do","upload");
    formData.append("type","program");
    formData.append("file",fileObj);
    var ii = layer.msg('正在上传中,请稍后...', {icon: 16, time: 10 * 1000});
    $.ajax({
        url: "ajax.php?act=uploadproimg",
        data: formData,
        type: "POST",
        dataType: "json",
        cache: false,
        processData: false,
        contentType: false,
        success: function (data) {
            layer.close(ii);
            if(data.code == 0){
                layer.msg('上传程序图标成功', {icon: 6});
                $("input[name='img']").val(data.url);
            }else{
                layer.alert(data.msg, {icon: 5});
            }
        },
        error:function(data){
            layer.msg('服务器错误', {icon: 5});
            return false;
        }
    })
}
function proedit() {
    var name = $("input[name='name']").val();
    var img = $("input[name='img']").val();
    var desc = $("textarea[name='desc']").val();
    var authfile = $("input[name='authfile']").val();
    var installer_name = $("input[name='installer_name']").val();
    var updater_name = $("input[name='updater_name']").val();
    var switchauth = $("select[name='switch']").val();
    var ipauth = $("select[name='ipauth']").val();
    var update = $("select[name='update']").val();
    var ver = $("input[name='ver']").val();
    var version = $("input[name='version']").val();
    var uplog = $("textarea[name='uplog']").val();
    var addblock = $("select[name='addblock']").val();
    var block = $("select[name='block']").val();
    var notauth_msg = $("textarea[name='notauth_msg']").val();
    var endauth_msg = $("textarea[name='endauth_msg']").val();
    var errauth_msg = $("textarea[name='errauth_msg']").val();
    var active = $("select[name='active']").val();
    var sqprice = $("input[name='sqprice']").val();
    var sqprice2 = $("input[name='sqprice2']").val();
    var sqprice3 = $("input[name='sqprice3']").val();
    var rzprice = $("input[name='rzprice']").val();
    var sqsprice = $("input[name='sqsprice']").val();
    var sqsprice2 = $("input[name='sqsprice2']").val();
    var cgprice = $("input[name='cgprice']").val();
    var ii = layer.msg('正在修改中,请稍后...', {icon: 16, time: 10 * 1000});
    $.ajax({
        type: "POST",
        url: "ajax.php?act=proedit&id=<?php echo $id;?>",
        data : {name:name,img:img,desc:desc,authfile:authfile,installer_name:installer_name,updater_name:updater_name,switchauth:switchauth,ipauth:ipauth,update:update,ver:ver,version:version,uplog:uplog,addblock:addblock,block:block,notauth_msg:notauth_msg,endauth_msg:endauth_msg,errauth_msg:errauth_msg,active:active,sqprice:sqprice,sqprice2:sqprice2,sqprice3:sqprice3,rzprice:rzprice,sqsprice:sqsprice,sqsprice2:sqsprice2,cgprice:cgprice},
        dataType: "json",
        success: function(data) {
            layer.close(ii);
            if (data.code == 0) {
                layer.msg(data.msg, {
                    icon: 6,
                    end: function (layero, index) {
                        window.location.reload();
                    }
                });
            } else {
                layer.msg(data.msg, {icon: 5});
            }
        },
        error:function(data){
            layer.msg('服务器错误', {icon: 5});
            return false;
        }
    });
    return false;
};
</script>
<?php
}else{
    sysmsg("参数错误",2,'./',true);
}
?>